<template>
	<view>
		<table>
			<tr>
				<td>id:{{data.ID}}</td>
				<td>价格</td>
				<td>重量</td>
				<td>存量</td>
				<td>商品名</td>
			</tr>
			<tr>
				<td>修改前</td>
				<td>{{data.Price}}</td>
				<td>{{data.Kilogram}}</td>
				<td>{{data.Stock}}</td>
				<td>{{data.Name}}</td>
			</tr>
			<tr>
				<td>修改后</td>
				<td><input type="text" value="" placeholder="请填写修改后的价格" v-model="price"/></td>
				<td><input type="text" value="" placeholder="请填写修改后的重量" v-model="kg"/></td>
				<td><input type="text" value="" placeholder="请填写修改后的存量" v-model="stock"/></td>
				<td><input type="text" value="" placeholder="请填写修改后的商品名" v-model="name"/></td>
			</tr>
		</table>
		<button type="default" @click="update()">修改</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:"",
				data:{},
				price:"",
				kg:"",
				stock:"",
				name:"",
			}
		},
		onLoad: function (option) {
				console.log(option.id);
				this.id=option.id
				this.list()
			},
		methods: {
			list(){
				uni.request({
				    url: 'http://127.0.0.1:8081/update', //仅为示例，并非真实接口地址。
				    data: {
				       id:this.id
				    },
				    header: {
				    },
				    success: (res) => {
				        console.log(res.data);
				        // this.text = 'request success';
						this.data=res.data.Data
				    }
				});
			},
			update(){
				uni.request({
				    url: 'http://127.0.0.1:8081/update', //仅为示例，并非真实接口地址。
					method:"POST",
				    data: {
				       id:this.id,
					   price:this.price,
					   kg:this.kg,
					   stock:this.stock,
					   name:this.name,
				    },
				     header: {"content-type":"application/x-www-form-urlencoded"},
				    success: (res) => {
				        console.log(res.data);
				        // this.text = 'request success';
						alert(res.data.Msg)
						uni.redirectTo({
							url: '../index/index'
						});
				    }
				});
			}
		},
	}
</script>

<style>

</style>
